<?php 

namespace pmvc\mvc\annotation;

use pmvc\annotation\AbstractAnnotation;

/**
 * An annotation that marks a class as an
 * {@link \pmvc\mvc\RequestFilter}.
 * 
 * @\pmvc\annotation\Params(names=["order", "url", "regex", "method", "params"])
 * @\pmvc\annotation\Locations(locations=[self::METHODS])
 */
class RequestFilterMapping
	extends AbstractAnnotation {
	
	const DELETE	= "DELETE";
	const GET		= "GET";
	const HEAD		= "HEAD";
	const OPTIONS	= "OPTIONS";
	const POST		= "POST";
	const PUT		= "PUT";
	const TRACE		= "TRACE";
	
	/**
	 * {@inheritDoc}
	 */
	protected function validateAndTransformParameter($name, $value) {
		switch($name) {
			case "method":
				if (!is_array($value)) {
					$value = Array($value);
				}
				$this->assertInArray($value, Array(
					self::DELETE,
					self::GET,
					self::HEAD,
					self::OPTIONS,
					self::POST,
					self::PUT,
					self::TRACE,
				));
				return $value;
			case "params":
				return (isset($value) && !is_array($value))
				? Array($value) : $value;
			default:
				return $value;
		}
	}
}

?>